package com.seo.controller.vender;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.commons.lang.StringUtils;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import com.github.pagehelper.PageInfo;
import com.seo.function.PageTool;
import com.seo.pojo.ReturnBody;
import com.seo.service.keyword.sdk.KeywordGService;
import com.seo.utils.Jurisdiction;

import lombok.extern.slf4j.Slf4j;

/**
 * @ClassName: GoodsController
 * @author rtc
 * @version 2018.07.28 12:20
 */
@Slf4j
@Controller
@RequestMapping(value = "/vender/")
public class venderGController {
	
	@Autowired
	private KeywordGService keywordGService;
	

	/*
	 * 厂商列表
	 */
	@RequestMapping("/list")
	public String list(@RequestParam Map<String, Object> pam,HttpServletRequest request, HttpSession session) {
		log.info("进入厂商列表...");
		List<Map<String, Object>> venderList = keywordGService.getVenderList(); //厂商列表
		request.setAttribute("venderList", venderList);
		return "keyWord/vender_list";

	}
	
	
	/**
	 * 删除厂商
	 * @param request
	 * @param session
	 * @return
	 */
	@RequestMapping("/delete")
	@ResponseBody
	public String delete(@RequestParam Map<String, Object> pam, HttpSession session) {
		log.info("进入厂商删除方法...");
		String msg = "";
		try {
			keywordGService.deleteVender(pam);
			msg = "true";
		} catch (Exception e) {
			msg = "error";
		}
		
		return msg;

	}

	/**
	 * 进入添加厂商页面
	 * @param userId
	 * @param request
	 * @return
	 */
	@RequestMapping("/addVenderPage")
	public String addVenderPage(@RequestParam Map<String, Object> pam, HttpServletRequest request) {
		log.info("进入添加厂商页面");
		request.setAttribute("action", "addVender");
		return "keyWord/vender_add";
	}
	
	@RequestMapping("/addVender")
	public String addVender(@RequestParam Map<String, Object> params, HttpServletRequest request) {
		log.info("添加厂商");
		ReturnBody rb = ReturnBody.init();
		rb = keywordGService.addVender(params);
		request.setAttribute("result", rb.getResult());
		return "save_result";
	}
}
